package org.pork.util;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;


public class AccountPosition {

	
//경도구하기
	public String getGpsX(String addr){
		
		URL url = null;
		HttpURLConnection con = null;
		InputStream is = null;
		SAXBuilder builder = null;    
		Document doc = null;
		Element root = null;
		String result = null;
		
		try{
			url = new URL("http://apis.daum.net/local/geo/addr2coord?" +
					"apikey=fab9d6e5a3cad853496a0cf1bedaeabfe60eb80e&" +
					"q="+URLEncoder.encode(addr,"utf-8")+"&output=xml");
			
			con = (HttpURLConnection) url.openConnection();
			is = con.getInputStream();
			builder = new SAXBuilder();
			doc = builder.build(is);
			root = doc.getRootElement();
			result = root.getChild("item").getChildText("lng");
	
		}catch(Exception e){
			e.printStackTrace();
		}
		
		
		return result;
	}
	
	//위도구하기
	public String getGpsY(String addr){
		
			URL url = null;
			HttpURLConnection con = null;
			InputStream is = null;
			SAXBuilder builder = null;
			Document doc = null;
			Element root = null;
			String result = null;
			
		try{
			
			url = new URL("http://apis.daum.net/local/geo/addr2coord?" +
					"apikey=fab9d6e5a3cad853496a0cf1bedaeabfe60eb80e" +
					"&q="+URLEncoder.encode(addr,"utf-8")+"&output=xml");
			con = (HttpURLConnection) url.openConnection();
			is = con.getInputStream();
			builder = new SAXBuilder();
			doc = builder.build(is);
			root = doc.getRootElement();
			result = root.getChild("item").getChildText("lat");
			
		}catch(Exception e){
			
			e.printStackTrace();
			
		}
			return result;
	}
}